package com.fishery.logistics.controller;


import com.fishery.entity.Result;
import com.fishery.logistics.service.PathService;
import com.sun.org.apache.regexp.internal.RE;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author run
 * @since 2021-01-23
 */
@Api(tags = "物流路径接口")
@CrossOrigin
@RestController
@RequestMapping("/logistics/path")
public class PathController {

    @Autowired
    private PathService pathService;

    @GetMapping("/{id}")
    @ApiOperation("根据物流订单id获取物流路径")
    public Result searchPathOfOrder(@PathVariable(value = "id") String orderId){
        return Result.success().data(pathService.searchPathOfOrder(orderId));
    }

    @PutMapping("/{orderId}/{stationId}")
    @ApiOperation("根据物流订单id和物流站点id执行入站操作")
    public Result inStation(@PathVariable(value = "orderId") String orderId
                             ,@PathVariable(value = "stationId") String stationId){
        return pathService.inStation(orderId,stationId)
                ? Result.success("操作成功") : Result.error("操作失败");
    }

    @PostMapping("/{orderId}/{stationId}")
    @ApiOperation("根据物流订单id和物流站点id执行出站操作")
    public Result outStation(@PathVariable(value = "orderId") String orderId
                                    ,@PathVariable(value = "stationId") String stationId){
        return pathService.outStation(orderId,stationId)
                ? Result.success("操作成功") : Result.error("操作失败");
    }
}

